package view;

import dao.EquipMsgDao;
import dao.UserDao;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import pojo.equip.EquipMsgEntity;
import view.admin.equipTypeManage.EquipTypeManageController;
import view.admin.equipManage.ChangeEquipController;
import view.admin.equipManage.EquipMsgManageController;
import view.admin.equipManage.NewEquipController;
import view.admin.logIn.AdminLoginController;
import view.admin.userManage.SetChangeUserController;
import view.admin.userManage.SetNewUserController;
import view.admin.factoryManage.FactoryManageController;
import view.admin.productMsgManage.ChangeProductController;
import view.admin.productMsgManage.MsgManageController;
import view.admin.productMsgManage.NewProductController;
import view.admin.productTypeManage.ProductTypeManageController;
import view.cloudFactory.*;
import view.admin.userManage.UserManageController;
import view.customer.BidManageController;
import view.customer.ChangeOrderController;
import view.customer.CustomerOrderController;
import view.customer.NewOrderController;
import view.register.RegisterController;
import view.welcome.WelcomeController;

import java.io.IOException;


public class Main extends Application {
    private static final Stage mainStage = new Stage();


    public Main() {
    }

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        FXMLLoader loader = new FXMLLoader(getClass().getResource("welcome\\WelcomeSample.fxml"));
        Parent root = loader.load();
        WelcomeController controller = loader.getController();
        controller.setApp(this);
        primaryStage.setTitle("FactorySystem");
        primaryStage.setScene(new Scene(root, 698, 456));
        primaryStage.show();
    }

    public void goToAdminLoginPage() throws Exception {
        FXMLLoader loader = new FXMLLoader(getClass().getResource("admin\\logIn\\AdminLoginSample.fxml"));
        Parent root = loader.load();
        AdminLoginController controller = loader.getController();
        controller.setApp(this);
        mainStage.setResizable(false);
        mainStage.setScene(new Scene(root, 900, 600));
        mainStage.show();
    }

    public void goToRegisterPage() throws Exception {
        FXMLLoader loader = new FXMLLoader(getClass().getResource("register\\RegisterSample.fxml"));
        Parent root = loader.load();
        RegisterController controller = loader.getController();
        controller.setApp(this);
        mainStage.setResizable(false);
        mainStage.setTitle("Register");
        mainStage.setScene(new Scene(root, 747, 555));
        mainStage.show();
    }

    public void goToAdminUserControllerPage() throws Exception {
        FXMLLoader loader = new FXMLLoader(getClass().getResource("admin\\userManage\\UserManage.fxml"));
        Parent root = loader.load();
        UserManageController controller = loader.getController();
        controller.setApp(this);
        mainStage.setResizable(false);
        mainStage.setScene(new Scene(root, 900, 600));
        mainStage.show();

    }

    public void goToSetNewUserPage() throws Exception {
        FXMLLoader loader = new FXMLLoader(getClass().getResource("admin\\userManage\\SetNewUserSample.fxml"));
        Parent root = loader.load();
        SetNewUserController controller = loader.getController();
        controller.setApp(this);
        mainStage.setResizable(false);
        mainStage.setScene(new Scene(root, 900, 600));
        mainStage.show();
    }

    public void goToSetChangeUserPage() throws Exception {
        FXMLLoader loader1 = new FXMLLoader(getClass().getResource("admin\\userManage\\UserManage.fxml"));
        Parent root1 = loader1.load();
        UserManageController controller1 = loader1.getController();
        controller1.setApp(this);

        FXMLLoader loader = new FXMLLoader(getClass().getResource("admin\\userManage\\SetChangeUser.fxml"));
        Parent root = loader.load();
        SetChangeUserController controller = loader.getController();
        controller.setApp(this);
        controller.setId(controller1.getId());
        controller.originDisplay();
        mainStage.setResizable(false);
        mainStage.setScene(new Scene(root, 900, 600));
        mainStage.show();

    }

    public void goToFactoryManagePage() throws Exception {
        FXMLLoader loader = new FXMLLoader(getClass().getResource("admin\\factoryManage\\FactoryManage.fxml"));
        Parent root = loader.load();
        FactoryManageController controller = loader.getController();
        controller.setApp(this);
        mainStage.setResizable(false);
        mainStage.setScene(new Scene(root, 900, 600));
        mainStage.show();
    }

    public void goToProductTypeManagePage() throws Exception {
        FXMLLoader loader = new FXMLLoader(getClass().getResource("admin\\productTypeManage\\productType.fxml"));
        Parent root = loader.load();
        ProductTypeManageController controller = loader.getController();
        controller.setApp(this);
        mainStage.setResizable(false);
        mainStage.setScene(new Scene(root, 900, 600));
        mainStage.show();
    }

    public void goToProductMsgManagePage() throws Exception {
        FXMLLoader loader = new FXMLLoader(getClass().getResource("admin\\productMsgManage\\MsgManage.fxml"));
        Parent root = loader.load();
        MsgManageController controller = loader.getController();
        controller.setApp(this);
        mainStage.setResizable(false);
        mainStage.setScene(new Scene(root, 900, 600));
        mainStage.show();
    }

    public void goToNewProductPage() throws IOException {
        FXMLLoader loader = new FXMLLoader(getClass().getResource("admin\\productMsgManage\\newProduct.fxml"));
        Parent root = loader.load();
        NewProductController controller = loader.getController();
        controller.setApp(this);
        mainStage.setResizable(false);
        mainStage.setScene(new Scene(root, 900, 600));
        mainStage.show();
    }

    public void goToChangeProductPage() throws Exception {
        FXMLLoader loader1 = new FXMLLoader(getClass().getResource("admin\\productMsgManage\\MsgManage.fxml"));
        Parent root1 = loader1.load();
        MsgManageController controller1 = loader1.getController();
        controller1.setApp(this);

        FXMLLoader loader = new FXMLLoader(getClass().getResource("admin\\productMsgManage\\ChangeProduct.fxml"));
        Parent root = loader.load();
        ChangeProductController controller = loader.getController();
        controller.setApp(this);
        controller.setId(controller1.getId());
        controller.originDisplay();
        mainStage.setResizable(false);
        mainStage.setScene(new Scene(root, 900, 600));
        mainStage.show();
    }

    public void goToEquipTypeManagePage() throws Exception {
        FXMLLoader loader = new FXMLLoader(getClass().getResource("admin\\equipTypeManage\\EquipTypeManage.fxml"));
        Parent root = loader.load();
        EquipTypeManageController controller = loader.getController();
        controller.setApp(this);
        mainStage.setResizable(false);
        mainStage.setScene(new Scene(root, 900, 600));
        mainStage.show();
    }

    public void goToEquipMsgManagePage() throws Exception {
        FXMLLoader loader = new FXMLLoader(getClass().getResource("admin\\equipManage\\EquipMsgManage.fxml"));
        Parent root = loader.load();
        EquipMsgManageController controller = loader.getController();
        controller.setApp(this);
        mainStage.setResizable(false);
        mainStage.setScene(new Scene(root, 900, 600));
        mainStage.show();
    }

    public void goToNewEquipPage() throws IOException {
        FXMLLoader loader = new FXMLLoader(getClass().getResource("admin\\equipManage\\NewEquip.fxml"));
        Parent root = loader.load();
        NewEquipController controller = loader.getController();
        controller.setApp(this);
        mainStage.setResizable(false);
        mainStage.setScene(new Scene(root, 900, 600));
        mainStage.show();
    }

    public void goToChangeEquipPage() throws Exception {
        FXMLLoader loader1 = new FXMLLoader(getClass().getResource("admin\\equipManage\\EquipMsgManage.fxml"));
        Parent root1 = loader1.load();
        EquipMsgManageController controller1 = loader1.getController();
        controller1.setApp(this);

        FXMLLoader loader = new FXMLLoader(getClass().getResource("admin\\equipManage\\ChangeEquip.fxml"));
        Parent root = loader.load();
        ChangeEquipController controller = loader.getController();
        controller.setApp(this);
        controller.setId(controller1.getId());
        controller.originDisplay();
        mainStage.setResizable(false);
        mainStage.setScene(new Scene(root, 900, 600));
        mainStage.show();
    }

    public void goToCloudFactoryManagePage() throws IOException {
        FXMLLoader loader1 = new FXMLLoader(getClass().getResource("welcome\\WelcomeSample.fxml"));
        Parent root1 = loader1.load();
        WelcomeController controller1 = loader1.getController();
        controller1.setApp(this);

        FXMLLoader loader = new FXMLLoader(getClass().getResource("cloudFactory\\cloudFactory.fxml"));
        Parent root = loader.load();
        cloudFactoryManageController controller = loader.getController();
        UserDao userDao = new UserDao();
        controller.setApp(this);
        controller.setFactoryName(userDao.findUser(controller1.getAccount()).getFactoryName());
        controller.showAllInfo();
        mainStage.setResizable(false);
        mainStage.setScene(new Scene(root, 900, 600));
        mainStage.show();
    }

    public void goToNewFactoryEquipPage() throws IOException {
        FXMLLoader loader1 = new FXMLLoader(getClass().getResource("cloudFactory\\cloudFactory.fxml"));
        Parent root1 = loader1.load();
        cloudFactoryManageController controller1 = loader1.getController();
        controller1.setApp(this);

        FXMLLoader loader = new FXMLLoader(getClass().getResource("cloudFactory\\NewFactoryEquip.fxml"));
        Parent root = loader.load();
        NewFactoryEquipController controller = loader.getController();
        controller.setApp(this);
        controller.setFactory(controller1.getFactoryName());
        mainStage.setResizable(false);
        mainStage.setScene(new Scene(root, 900, 600));
        mainStage.show();
    }

    public void goToChangeFactoryEquipPage() throws Exception {
        FXMLLoader loader1 = new FXMLLoader(getClass().getResource("cloudFactory\\cloudFactory.fxml"));
        Parent root1 = loader1.load();
        cloudFactoryManageController controller1 = loader1.getController();
        controller1.setApp(this);

        FXMLLoader loader = new FXMLLoader(getClass().getResource("cloudFactory\\ChangeFactoryEquip.fxml"));
        Parent root = loader.load();
        ChangeFactoryEquipController controller = loader.getController();
        controller.setApp(this);
        controller.setId(controller1.getId());
        controller.setFactory(controller1.getFactoryName());
        controller.originDisplay();
        mainStage.setResizable(false);
        mainStage.setScene(new Scene(root, 900, 600));
        mainStage.show();
    }

    public void goToRentEquipPage() throws IOException {
        FXMLLoader loader1 = new FXMLLoader(getClass().getResource("cloudFactory\\cloudFactory.fxml"));
        Parent root1 = loader1.load();
        cloudFactoryManageController controller1 = loader1.getController();
        controller1.setApp(this);

        FXMLLoader loader = new FXMLLoader(getClass().getResource("cloudFactory\\RentEquip.fxml"));
        Parent root = loader.load();
        RentEquipController controller = loader.getController();
        controller.setApp(this);
        controller.setId(controller1.getUserId());
        mainStage.setResizable(false);
        mainStage.setScene(new Scene(root, 900, 600));
        mainStage.show();
    }

    public void goToAddProduct() throws Exception {
        FXMLLoader loader1 = new FXMLLoader(getClass().getResource("cloudFactory\\cloudFactory.fxml"));
        Parent root1 = loader1.load();
        cloudFactoryManageController controller1 = loader1.getController();
        controller1.setApp(this);

        FXMLLoader loader = new FXMLLoader(getClass().getResource("cloudFactory\\AddProduct.fxml"));
        Parent root = loader.load();
        AddProductController controller = loader.getController();
        controller.setApp(this);
        controller.setId(controller1.getId());
        controller.originDisplay();
        mainStage.setResizable(false);
        mainStage.setScene(new Scene(root, 900, 600));
        mainStage.show();
    }

    public void goToCustomerOrderPage() throws IOException {
        FXMLLoader loader1 = new FXMLLoader(getClass().getResource("welcome\\WelcomeSample.fxml"));
        Parent root1 = loader1.load();
        WelcomeController controller1 = loader1.getController();
        controller1.setApp(this);

        FXMLLoader loader = new FXMLLoader(getClass().getResource("customer\\CustomerOrder.fxml"));
        Parent root = loader.load();
        CustomerOrderController controller = loader.getController();
        UserDao userDao = new UserDao();
        controller.setApp(this);
        controller.setUserid(userDao.findUser(controller1.getAccount()).getId());
        controller.showAllInfo();
        mainStage.setResizable(false);
        mainStage.setScene(new Scene(root, 900, 600));
        mainStage.show();
    }

    public void goToNewOrderPage() throws IOException {
        FXMLLoader loader1 = new FXMLLoader(getClass().getResource("customer\\CustomerOrder.fxml"));
        Parent root1 = loader1.load();
        CustomerOrderController controller1 = loader1.getController();
        controller1.setApp(this);

        FXMLLoader loader = new FXMLLoader(getClass().getResource("customer\\NewOrder.fxml"));
        Parent root = loader.load();
        NewOrderController controller = loader.getController();
        controller.setApp(this);
        controller.setUserId(controller1.getUserid());
        mainStage.setResizable(false);
        mainStage.setScene(new Scene(root, 900, 600));
        mainStage.show();
    }

    public void goToChangeOrderPage() throws Exception {
        FXMLLoader loader1 = new FXMLLoader(getClass().getResource("customer\\CustomerOrder.fxml"));
        Parent root1 = loader1.load();
        CustomerOrderController controller1 = loader1.getController();
        controller1.setApp(this);

        FXMLLoader loader = new FXMLLoader(getClass().getResource("customer\\ChangeOrder.fxml"));
        Parent root = loader.load();
        ChangeOrderController controller = loader.getController();
        controller.setApp(this);
        controller.setId(controller1.getId());
        controller.setUserId(controller1.getUserid());
        controller.originDisplay();
        mainStage.setResizable(false);
        mainStage.setScene(new Scene(root, 900, 600));
        mainStage.show();
    }

    public void goToFactoryOrderPage() throws Exception {
        FXMLLoader loader1 = new FXMLLoader(getClass().getResource("cloudFactory\\cloudFactory.fxml"));
        Parent root1 = loader1.load();
        cloudFactoryManageController controller1 = loader1.getController();
        controller1.setApp(this);

        FXMLLoader loader = new FXMLLoader(getClass().getResource("cloudFactory\\FactoryOrder.fxml"));
        Parent root = loader.load();
        FactoryOrderController controller = loader.getController();
        controller.setApp(this);
        controller.setId(controller1.getUserId());
        controller.setFactory(controller1.getFactoryName());
        controller.showAllInfo();
        mainStage.setResizable(false);
        mainStage.setScene(new Scene(root, 900, 600));
        mainStage.show();
    }

    public void goToAddBidPage() throws IOException {
        FXMLLoader loader1 = new FXMLLoader(getClass().getResource("cloudFactory\\FactoryOrder.fxml"));
        Parent root1 = loader1.load();
        FactoryOrderController controller1 = loader1.getController();
        controller1.setApp(this);

        FXMLLoader loader = new FXMLLoader(getClass().getResource("cloudFactory\\AddBidPrice.fxml"));
        Parent root = loader.load();
        AddBidPriceController controller = loader.getController();
        controller.setApp(this);
        controller.setOrderId(controller1.getId());
        controller.setFactory(controller1.getFactory());
        Stage stage = new Stage();
        stage.setScene(new Scene(root, 420, 242));
        stage.show();
    }

    public void goToCustomerBidManage() throws IOException {
        FXMLLoader loader1 = new FXMLLoader(getClass().getResource("customer\\CustomerOrder.fxml"));
        Parent root1 = loader1.load();
        CustomerOrderController controller1 = loader1.getController();
        controller1.setApp(this);

        FXMLLoader loader = new FXMLLoader(getClass().getResource("customer\\BidManage.fxml"));
        Parent root = loader.load();
        BidManageController controller = loader.getController();
        controller.setApp(this);
        controller.setUserId(controller1.getUserid());
        controller.setOrderId(controller1.getId());
        controller.showAllInfo();
        mainStage.setResizable(false);
        mainStage.setScene(new Scene(root, 900, 600));
        mainStage.show();

    }

    public void goToPaiChanPage() throws IOException {
        FXMLLoader loader = new FXMLLoader(getClass().getResource("cloudFactory\\addEquipForBid.fxml"));
        Parent root = loader.load();
        addEquipForBidController controller = loader.getController();
        controller.setApp(this);
        mainStage.setResizable(false);
        mainStage.setScene(new Scene(root, 900, 600));
        mainStage.show();
    }


}


